import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
import joblib

def train_model(df):
    """模型训练"""
    X = df.drop(columns=['target'])
    y = df['target']
    
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    
    model = RandomForestClassifier(n_estimators=100, random_state=42)
    model.fit(X_train, y_train)
    
    return model

def save_model(model, file_path):
    """保存训练好的模型"""
    joblib.dump(model, file_path)

if __name__ == "__main__":
    features_data_path = "data/processed/ssq/features_data.csv"
    model_path = "models/ssq/lottery_model.pkl"

    df = pd.read_csv(features_data_path)
    model = train_model(df)
    save_model(model, model_path)